import { customTable } from "@/components/ProTable/interface";
import { ProTableValue } from "@/interface/public";
/**
 *@name
 */
export const useDataGrid = (proTableBox: ProTableValue) => {
  const { modalParams, openDialog } = useModal();
  const dataGrid = reactive<customTable>({
    initParam: {
      id: ""
    },
    useData: false,
    columns: [
      {
        prop: "_title",
        label: "类型"
      },
      {
        prop: "-",
        label: ""
      },
      {
        prop: "text",
        label: ""
      }
    ],
    rowButtonList: [
      {
        label: "复制",
        icon: "icon-fenxiang",
        hide: true,
        method: item => {
          uni.setClipboardData({
            data: item.text
          });
        },
        displayPosition: 1
      },
      {
        label: "删除",
        icon: "icon-shanchu1",
        hide: true,
        method: item => {
          openDialog(`确定删除日志?`, dayLogDeleteDayLog, { id: item.id }, proTableBox.value.getTableList);
        },
        displayPosition: 1
      }
    ]
  });

  const dataCallback = data => {
    console.log(data, "data");
    data.records = data.records.map(item => {
      console.log(item, "item");

      item._title = `${item.type} ${item.date}`;
      return item;
    });
    return data;
  };

  return {
    dataGrid,
    dataCallback,
    modalParams
  };
};
